<?php
/**
 *  
 * @package package_name
 * @author Mervin.Wong<mervin0502@163.com>
 * @copyright
 * @license  http://www.apache.org/licenses/LICENSE-2.0
 * @version 0.1.0
 * @date 2013-3-7下午7:16:37
 *
 */
 /**
  * CanGoo Attachment_model Model
  */
 class Attachment_model extends CI_Model{
 	
 	public function __construct(){
 		parent::__construct();
 		$this->load->database();
 	}
 	
 	public function get_one($field, $table, $conditions){
 		$this->db->select($field);
 		$this->db->from($table);
 		foreach($conditions as $k=>$v){
 			$this->db->where($k, $v);
 		}
 		$query = $this->db->get();
 		if($query->num_rows > 0){
 			return $query->row_array();
 		}else{
 			return false;
 		}
 	}
 	
 	public function get_all($field, $table, $conditions = '', $ffset, $limit, $order = ''){
 		$this->db->select($field);
 		$this->db->from($table);
 		if(!empty($conditions)){
 			foreach($conditions as $k=>$v){
 				$this->db->where($k, $v);
 			}
 		}
 		if(!empty($order)){
 			foreach($order as $k=>$v){
 				$this->db->order_by($k, $v);
 			}
 		}
 		$this->db->limit($limit, $ffset);
 		$query = $this->db->get();
 		if($query->num_rows > 0){
 			return $query->result_array();
 		}else{
 			return false;
 		}
 	}
 	
 	public function get_num($field, $table, $conditions){
 		$this->db->select();
 		$this->db->from($table);
 		if(!empty($conditions)){
 			foreach($conditions as $k=>$v){
 				$this->db->where($k, $v);
 			}
 		}
 		$query = $this->db->get();
 		return $query->num_rows;
 	}
 	
 	
 	public function get_posts($aid){
 		
 		
 	}
 	public function insert($field, $table){
 		$this->db->insert($table, $field);
 		if($this->db->affected_rows() > 0){
 			return $this->db->insert_id();
 		}else{
 			return false;
 		}
 	}
 	
 	public function update($field, $table, $conditions){
 		foreach($conditions as $k=>$v){
 			$this->db->where($k, $v);
 		}
 		$this->db->update($table, $field);
 		if($this->db->affected_rows() > 0){
 			return true;
 		}else{
 			return false;
 		}
 	}
 	
 	public function delete($table, $conditions){
 		foreach($conditions as $k=>$v){
 			$this->db->where($k, $v);
 		}
 		$this->db->delete($table);
 	}
 }

/* End of file attachment_model.php */
/* Location ./admin/models/attachment_model.php */
